package iotest.byteio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class BufferInputStreamDemo {
	public static void main(String[] args) {
		inputbyte();
	}
	
	private static void inputbyte2() {
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream("byte.txt");
			byte[] bs = new byte[10];
			
			int num =-1;
			while (( num = inputStream.read(bs))!=-1) {
				System.out.print(new String(bs,0,num));
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if (inputStream!=null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	private static void inputbyte1() {
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream("byte.txt");
			byte[] bs = new byte[1024];
			int num = inputStream.read(bs);
			
			System.out.println(new String(bs));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if (inputStream!=null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	private static void inputbyte() {
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream("byte.txt");
			int num = inputStream.read();
			
			System.out.println((char)num);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if (inputStream!=null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
